

import {observable, action} from "mobx";
import request from "../utils/request";
import * as api from "../api/api";
import {LoadHoc, loading} from '../hoc/loadHoc';

export default class HomeStore extends LoadHoc {
  /**
   * 首页数据
   */
  @observable home: api.SingleUserMallMallVOHomeVO = {};

  @loading @action
  async getHomeInfo(params: {
    callback?: (home: api.SingleUserMallMallVOHomeVO) => void;
  }) {
    const {callback} = params;
    const home = await request(api.AppmallApiFetchParamCreactor.appmallGetHomeAsync({}));
    this.home = home;
    callback && callback(home);
  }

  /**
   * 常见问题
   */
  @observable allHeadLines: api.SingleUserMallHeadLineVOHeadlineAppVO = {};

  @loading @action
  async getAllHeadLines(params: {
    formCategoryName: string,
    pageIndex: number,
    pageSize: number,
    callback?: (res: api.SingleUserMallHeadLineVOHeadlineAppVO) => void;
  }) {
    const {formCategoryName, pageIndex, pageSize, callback} = params;
    const allHeadLines = await request(api.AppheadLinesApiFetchParamCreactor.appheadLinesGetAllHeadLinesAsync({
      formCategoryName,
      formSkipCount: (pageIndex-1)*pageSize,
      formMaxResultCount: pageSize
    }));
    this.allHeadLines = allHeadLines;
    callback && callback(allHeadLines);
  }

  /**
   * 用户会员等级升级
   */
  @observable allPrivilegeTypes: api.SingleUserMallPrivilegesVOPrivilegeTypeVO = {};

  @loading @action
  async getAllPrivilegeTypes(params: {
    callback?: (res: api.SingleUserMallPrivilegesVOPrivilegeTypeVO) => void;
  }) {
    const {callback} = params;
    const allPrivilegeTypes = await request(api.AppprivilegeApiFetchParamCreactor.appprivilegeGetAllPrivilegeTypesAsync({}));
    this.allPrivilegeTypes = allPrivilegeTypes;
    callback && callback(allPrivilegeTypes);
  }

  /**
   * 用户注册协议
   */
  @observable serviceAgreement: api.SingleUserMallHeadLineVOHeadlineAppVO = {};

  @loading @action
  async getServiceAgreement(params: {
    callback?: (res: api.SingleUserMallHeadLineVOHeadlineAppVO) => void;
  }) {
    const {callback} = params;
    const serviceAgreement = await request(api.AppheadLinesApiFetchParamCreactor.appheadLinesGetServiceAgreement({}));
    this.serviceAgreement = serviceAgreement;
    callback && callback(serviceAgreement);
  }

  /**
   * 关于我们
   */
  @observable aboutUs: api.SingleUserMallHeadLineVOHeadlineAppVO = {};

  @loading @action
  async getAboutUs(params: {
    callback?: (res: api.SingleUserMallHeadLineVOHeadlineAppVO) => void;
  }) {
    const {callback} = params;
    const aboutUs = await request(api.AppheadLinesApiFetchParamCreactor.appheadLinesGetAboutUs({}));
    this.aboutUs = aboutUs;
    callback && callback(aboutUs);
  }

  /**
   * 获取快递费
   */
  @loading @action
  async getFreight(params: {
    callback?: (res: number) => void;
  }) {
    const {callback} = params;
    const freight = await request(api.AppstoreSettingApiFetchParamCreactor.appstoreSettingGetExpressCharges({}));
    callback && callback(freight);
  }



  /**
   * 根据规格ID和年份获取报税价格
   */
  @loading @action
  async getTaxPrice(params: {
    isRegister,
    createYear: string,
    carSkuCategoryId: number,
    quality: number,
    carType: number,
    callback?: (res: number) => void;
  }) {
    const {isRegister,createYear, carSkuCategoryId, quality,carType, callback} = params;
    const taxPrice = await request(api.ApporderApiFetchParamCreactor.apporderGetCarTaxPric({
      formIsRegister: isRegister,
      formCarSkuCategoryId: carSkuCategoryId,
      formCreateYear: createYear,
      formCarType: carType,
      formQuality: quality
    }));
    callback && callback(taxPrice);
  }

  /**
   * 电子税票下载
   */
  @loading @action
  async getCarTaxPicture(params: {
    id: number,
    callback?: (res: number) => void;
  }) {
    const { id, callback } = params;
    const carTaxPicture = await request(api.ApporderApiFetchParamCreactor.apporderGetCarTaxPicture({
      formId: id
    }));
    callback && callback(carTaxPicture);
  }

  /**
   * 驳回订单修改
   */
  @loading @action
  async updateOrder(params: {
    form: {
      carDrivePicture: string,
      carDrivePictureTwo: string,
      carUserPicture: string,
      carUserPictureTwo: string,
      buyCarPicture: string,
      carStandardPicture: string,
      id: number
    },
    callback?: (res: number) => void;
  }) {
    const { form, callback } = params;
    const carTaxPicture = await request(api.ApporderApiFetchParamCreactor.apporderUpdateOrderAsync({
      form
    }));
    callback && callback(carTaxPicture);
  }

  /**
   * 获取订单详情
   */
  @loading @action
  async getOrder(params: {
    formId: number,
    callback?: (res: number) => void;
  }) {
    const { formId, callback } = params;
    const carTaxPicture = await request(api.ApporderApiFetchParamCreactor.apporderGetOrderAsync({
      formId
    }));
    callback && callback(carTaxPicture);
  }
}
